package ex3.render.raytrace;

import java.util.Map;
import math.Vec;

public class Material implements IInitable
{
	 
	// material property vectors
	protected Vec diffuse = new Vec(0.7, 0.7, 0.7);
	protected Vec ambient = new Vec(0.1, 0.1, 0.1);
	protected Vec specular = new Vec(1, 1, 1);
	protected Vec emission = new Vec(0, 0, 0);
	// light shininess/reflectance default values
	protected double shininess = 100;
	protected double reflectance = 0;


    /**
     * Constructor, creates new material object using property vectors 
     * and parsed XML data
     * @param attributes, taken from XML
     */
    public Material(Map <String, String> attributes)
    {
        // parse XML data
        if(attributes.containsKey("mtl-diffuse"))
            diffuse = new Vec(attributes.get("mtl-diffuse"));
        if(attributes.containsKey("mtl-specular"))
            specular = new Vec(attributes.get("mtl-specular"));
        if(attributes.containsKey("mtl-emission"))
            emission = new Vec(attributes.get("mtl-emission"));
        if(attributes.containsKey("mtl-ambient"))
            ambient = new Vec(attributes.get("mtl-ambient"));
        if(attributes.containsKey("reflectance"))
            reflectance = Double.valueOf(attributes.get("reflectance")).doubleValue();
        if(attributes.containsKey("mtl-shininess"))
            shininess = Double.valueOf(attributes.get("mtl-shininess")).doubleValue();
    }
    
    /**
     * Generic constructor, to be used in conjunction with init
     */
    public Material() {}

	@Override
	public void init(Map <String, String> attributes) {
        // parse XML data
        if(attributes.containsKey("mtl-diffuse"))
            diffuse = new Vec(attributes.get("mtl-diffuse"));
        if(attributes.containsKey("mtl-specular"))
            specular = new Vec(attributes.get("mtl-specular"));
        if(attributes.containsKey("mtl-emission"))
            emission = new Vec(attributes.get("mtl-emission"));
        if(attributes.containsKey("mtl-ambient"))
            ambient = new Vec(attributes.get("mtl-ambient"));
        if(attributes.containsKey("reflectance"))
            reflectance = Double.valueOf(attributes.get("reflectance")).doubleValue();
        if(attributes.containsKey("mtl-shininess"))
            shininess = Double.valueOf(attributes.get("mtl-shininess")).doubleValue();
		
	}
}